package com.jic.filecenter.common;

import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * @author zhoufeng
 * @Description: 文件下载工具类
 * @date 2020-03-12 18:57
 */
public class FileUtil {
    public static void download(String filename,String filePath, HttpServletResponse res) throws IOException {
        // 发送给客户端的数据
        OutputStream outputStream = res.getOutputStream();
        byte[] buff = new byte[1024];
        BufferedInputStream bis = null;
        // 读取filename
        bis = new BufferedInputStream(new FileInputStream(new File(filePath + "/" + filename)));
        int i = bis.read(buff);
        while (i != -1) {
            outputStream.write(buff, 0, buff.length);
            outputStream.flush();
            i = bis.read(buff);
        }
    }
}
